﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using CommonObjects;
using Microsoft.Kinect;

namespace SketlonBackOffice
{
    public static class LineHelpers
    {
        public static void DrawLine(Button Joint1, Button Joint2, Canvas wrapperCanvas,Line line)
        {
            Point headpoint = Joint1.TransformToAncestor(wrapperCanvas).Transform(new Point(0, 0));
            Point shouldercenterjoint = Joint2.TransformToAncestor(wrapperCanvas).Transform(new Point(0, 0));
            line.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
            line.X1 = headpoint.X.AdjustCenterX();
            line.X2 = shouldercenterjoint.X.AdjustCenterX();
            line.Y1 = headpoint.Y.AdjustCenterY();
            line.Y2 = shouldercenterjoint.Y.AdjustCenterY();
            line.StrokeThickness = 2;
            wrapperCanvas.Children.Add(line);
        }
        public static double GetDegree(Line line1)
        {
            double slope1;
            double tangent;
            slope1 = (line1.Y1 - line1.Y2) / (line1.X1 - line1.X2);
            if (double.IsInfinity(slope1))
            {
                slope1 = 0;
                return 90;
            }
            
            tangent =slope1 ;
            return RadianToDegree(Math.Atan(tangent));
        }
        public static double GetDegree(SkeletonPoint p1,SkeletonPoint p2)
        {
            double slope1;
            double tangent;
            slope1 = (p1.Y - p2.Y) / (p1.X - p2.X);
            if (double.IsInfinity(slope1))
            {
                slope1 = 0;
                return 90;
            }

            tangent = slope1;
            double value=RadianToDegree(Math.Atan(tangent));
            if(value<0)
                value=value*(-1);
            return value;
        }
        private static double RadianToDegree(double angle)
        {
            return angle * (180.0 / Math.PI);
        }
    }
}
